import {NavigationFailure, RouteLocationNormalized} from "vue-router";
import {CustomRouterOptions} from "./app-router-type";

export default (
    to: RouteLocationNormalized,
    from: RouteLocationNormalized,
    customRouterOptions: Required<CustomRouterOptions>,
    failure?: NavigationFailure | void
) => {
  if (
      typeof customRouterOptions.showLoading === "function"
          ? customRouterOptions.showLoading()
          : customRouterOptions.showLoading
  ) {
    customRouterOptions.hideLoadingFunction(!failure);
  }

  customRouterOptions.afterEach(to, from, failure);
};
